package com.leetcode.partition21;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/1/27 19:38
 */
public class LC2047句子中的有效单词数 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String sentence = reader.readLine();
        writer.write(countValidWords(sentence) + "\n");
        writer.flush();
    }

    public static int countValidWords(String sentence) {
        String[] sen = sentence.split(" ");
        int ans = 0;
        for (String s : sen) {
            if (check(s)) ans++;
        }
        return ans;
    }

    private static boolean check(String s) {
        int n = s.length();
        if (n == 0) return false;
        for (int i = 0, cnt1 = 0, cnt2 = 0; i < n; i++) {
            char c = s.charAt(i);
            if (c == ' ') return false;
            if (Character.isDigit(c)) return false;
            if (c == '-') {
                cnt1++;
                if (cnt1 > 1 || i == 0 || i == n - 1) return false;
                //连字符前后如果不是字母也不合法
                if (!Character.isLetter(s.charAt(i - 1)) || !Character.isLetter(s.charAt(i + 1))) return false;
            }
            if (c == '!' || c == ',' || c == '.') {
                cnt2++;
                if (cnt2 > 1 || i != n - 1) return false;
            }
        }
        return true;
    }
}
